#ifndef NARRATIONNODE_H
#define NARRATIONNODE_H

#include <QObject>
#include <QVector2D>
#include "Render/rendertarget.h"
#include <QObject>
#include <QMap>
#include <QPushButton>
#include "eventcenter.h"
#include "Linker/linker.h"
struct BGM{
public:
    QString path = "";
    bool loop = false;//循环播放
    BGM(QString p = "",bool l = false){
        path = p;
        loop = l;
    }
    BGM(const BGM& bgm)
    {
        this->path = bgm.path;
        this->loop = bgm.loop;
    }
};
class NarrationNode;

class NarrationNode:public QObject
{
        Q_OBJECT
public:
    NarrationNode();
    //拷贝构造
    NarrationNode(const NarrationNode& node);
    ~NarrationNode();
    void SetBackGround(QString* p,QVector2D* ndc,float sizeTimes);
    void AddImage(QString* p,QVector2D* ndc,float sizeTimes,int layer);
    void SetBgm(QString* p,bool loop = false,bool stop = false);
    void SetBgse(QString* p,bool loop = false,bool stop = false);
    void SetSound(QString soundPath);
    void AddOption();
    void SetName(QString name);
    void SetText(QString text);
    bool RemoveLinkerAt(int index);
    void RemoveImage(int layer);

    int parentId = -1;
    int childId = -1;

    QVector<RenderTarget*> image;
    //名字可以重复，id是唯一的
    QString nodeName = "备注";
    //声音路径为空表示接着刚刚的放下去
    BGM* bgm = nullptr;
    BGM* bgse = nullptr;
    bool stopBgm = false;
    bool stopBgse = false;
    QString soundPath = "";
    QString name = "角色";
    QString text = "对话";
    int id = 0;
    QVector<Linker*> linkers;
    bool effect = false;
    QString effectName = "";
    bool black = false;
    int blackTime = 0;
};
class NarrationTree:public QObject
{
    Q_OBJECT
public:
    NarrationTree(const NarrationTree&) = delete;
    NarrationTree& operator=(const NarrationTree&) = delete;
    static NarrationTree& Instance();
    ~NarrationTree();
    QMap<int,NarrationNode*> narrationTree;
    void AddNode(NarrationNode* node);
    NarrationNode* InitTree();
    //数据持久化
    void SaveTree();
    void DeleteNode(int id);
private:
    NarrationTree();

};

#endif // NARRATIONNODE_H
